package com.leo.collisions;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.physics.CollisionHandler;
import com.leo.TankApp;
import com.leo.common.GameType;
import com.leo.component.FlagComponent;

/**
 * 子弹和旗帜的碰撞检测
 */
public class BulletFlagHandler extends CollisionHandler {

    public BulletFlagHandler() {
        super(GameType.BULLET, GameType.FLAG);
    }

    @Override
    protected void onCollisionBegin(Entity a, Entity b) {
        // 碰撞
        b.getComponent(FlagComponent.class).onHit();
        FXGL.spawn("explode", b.getCenter().subtract(50 / 2.0, 50 / 2.0));
        a.removeFromWorld();
        // 弹出失败场景
        FXGL.<TankApp>getAppCast().gameOver();
    }
}
